package com.briup.ptp.web.controller;

import com.briup.ptp.entity.Employee;
import com.briup.ptp.service.EmployeeService;
import com.briup.ptp.utils.Result;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author :xuyang
 * @DateTime:2024/2/19 20:27
 * @Version :v1.0.0
 * ClassName:EmployeeController
 * Package  :com.briup.ptp.web.controller
 * Description:TODO
 */
@RestController
@RequestMapping("/employee")
@Api(tags = "员工管理相关接口")
@CrossOrigin
public class EmployeeController {
    @Autowired
    private EmployeeService service;

    @PostMapping("/page")
    @ApiOperation("分页+条件查询员工信息")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "name", value = "员工名字", paramType = "query", required = false),
                    @ApiImplicitParam(name = "position", value = "员工职位", paramType = "query", required = false),
                    @ApiImplicitParam(name = "health", value = "健康状况", paramType = "query", required = false),
                    @ApiImplicitParam(name = "pageNum", value = "当前页码", paramType = "query", required = true),
                    @ApiImplicitParam(name = "pageSize", value = "每页大小", paramType = "query", required = true),

            }
    )
    public Result page(String name, String position, String health, Integer pageNum, Integer pageSize) {
        PageInfo<Employee> pages = service.page(name, position, health, pageNum, pageSize);
        return Result.success(pages);
    }

    @PostMapping("/saveOrUpdate")
    @ApiOperation("新增+修改员工信息")
    public Result saveOrUpdate(@RequestBody Employee employee) {
//        int saveOrUpdateEmployee = service.saveOrUpdateEmployee(employee);
        service.saveOrUpdateEmployee(employee);
        return Result.success();
    }

    @DeleteMapping("/deleteById/{id}")
    @ApiOperation("根据员工id删除员工信息")
    public Result deleteById(@PathVariable Integer id) {
        service.deleteById(id);
        return Result.success();
    }

    @DeleteMapping("deleteByIdAll")
    @ApiOperation("批量删除员工信息")
    public Result deleteByIdAll(@RequestParam("employee_ids") List<Integer> ids) {
        service.removeByIds(ids);
        return Result.success();
    }
}
